package com.credithc.eagleeye.api.interceptor;
import com.credithc.eagleeye.api.utils.ServletUtils;
import com.credithc.eagleeye.api.vo.AuthTokenVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 描 述: <br/>
 * 作 者: zhangjin<br/>
 * 创 建：2018年12月04日<br/>
 * 版 本：v1.0.0<br>
 * <p>
 * 历 史: (版本) 作者 时间 注释 <br/>
 */
@Component
public class TokenHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if(StringUtils.equals("OPTIONS",request.getMethod())){
            return true;
        }
        AuthTokenVo authTokenVo = ServletUtils.getAuthTokenVo(request);
        if(authTokenVo==null) {
            return false;
        }
        return true;
    }
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    }
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
    }
}
